﻿using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using WSDZ.KM.ZH.XiaoManIntegrating40;

namespace XiaoManTestClient
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            InitEvent();
        }
        public void InitEvent()
        {
            btn1.Click += (s, e) => {

                //string txt = File.ReadAllText($@"D:\A1\1.txt");
                //JObject obj = JObject.Parse(txt);
                //JObject dataObj = JsonConvert.DeserializeObject<JObject>(obj["data"].ToStringV1());
                //JArray companyArray = JsonConvert.DeserializeObject<JArray>(dataObj["company"].ToStringV1());
                //if (companyArray==null|| companyArray.Count<1)
                //    return;
                //List<XMFieldData> xmdatas = new List<XMFieldData>();
                //foreach (JObject item in companyArray)
                //{
                //    JArray fieldArray = JsonConvert.DeserializeObject<JArray>(item["fields"].ToStringV1());
                //    if (fieldArray == null || fieldArray.Count < 1)
                //        continue ;
                //    foreach (JObject fielddata in fieldArray)
                //    {
                //        XMFieldData xmd = new XMFieldData();
                //        xmd.group_id = item["group_id"].ToStringV1();
                //        xmd.group_name = item["group_name"].ToStringV1();
                //        xmd.id = fielddata["id"].ToStringV1();
                //        xmd.name = fielddata["name"].ToStringV1();
                //        xmd.field_type = fielddata["field_type"].ToStringV1();
                //        xmd.value = fielddata["value"].ToStringV1();
                //        xmdatas.Add(xmd);
                //    }
                //}
                //string isUpdateToK3 = GetValueByKey("38669239529883",xmdatas);
                //string address = GetValueByKey("address", xmdatas);
                //string xiaomanValue = GetValueByKey("35249210606679", xmdatas);

            };
            btn2.Click += (s, e) => {

                //XiaoManCustomerManager manager = new XiaoManCustomerManager();
                //manager.Main();
                //bool isUpdateToK3 = "38669239529883".GetValueByKey(companyArray, "1") == "是";
                //string address = "address".GetValueByKey(companyArray, "4");
                //string xiaomanValue = "35249210606679".GetValueByKey(companyArray, "5");
            };
        }
        //public string GetValueByKey(string key, List<XMFieldData> xmdatas)
        //{
        //    try
        //    {
        //        if (xmdatas == null || xmdatas.Count < 1)
        //            return "";
        //        XMFieldData obj = xmdatas.Where(x => x.id.EqualsV1(key)).FirstOrDefault();
        //        return obj == null ? "" : obj.value;
        //    }
        //    catch (Exception)
        //    {
        //        return "";
        //    }
        //}
    }
    //public class XMFieldData
    //{
    //    public string group_id { get; set; }
    //    public string group_name { get; set; }
    //    public string id { get; set; }
    //    public string name { get; set; }
    //    public string field_type { get; set; }
    //    public string value { get; set; }
    //}
}
